var flipNum = function(dom){
	var clock1 = new FlipClock(dom, 0, {
			clockFace: 'Counter',
			minimumDigits: 5
		});
	return clock1;
};

var hostNum = function(k, fn) {
		$.ajax({
			url: getRequstURL(k),
			type: 'GET',
			success: function(res){
				var n = 0;
				if(k == "triggers") {
						if(res && res.triggers) {
								n = res.triggers;
						}
				} else {
					if($.isArray(res)){
							n = res.length;
					}
				}
				
				fn && fn(n);
			},
			error: function(error){
				console.log(error)
			}
		});
};

var c1 = flipNum($('.white_num_one')),
		c2 = flipNum($('.white_num_two')),
		c3 = flipNum($('.white_num_three'));

var randomNum = function() {
			var num = parseInt(Math.random() * 900) + 100;
			return num;
	}

var numInit = function() {
		c1.setValue(388);
		hostNum('hosts',function(n){
				c2.setValue(n);
		});
		hostNum('triggers',function(n){
				c3.setValue(n);
	});
};

var flipNumInit = function(s) {
		numInit();
		setInterval(function(){
				numInit();
		}, s * 1000)
};